Is `catch(...) { throw; }` a bad practice?
Posted
by
ereOn
on Programmers
See other posts from Programmers
or by ereOn
Published on 2011-12-05T09:05:07Z
Indexed on
2012/09/24
21:49 UTC
Read the original article
Hit count: 144
c++
While I agree that catching ...
without rethrowing is indeed wrong, I however believe that using constructs like this:
try
{
// Stuff
}
catch (...)
{
// Some cleanup
throw;
}
Is acceptable in cases where RAII is not applicable. (Please, don't ask... not everybody in my company likes object-oriented programming and RAII is often seen as "useless school stuff"...)
My coworkers says that you should always know what exceptions are to be thrown and that you can always use constructs like:
try
{
// Stuff
}
catch (exception_type1&)
{
// Some cleanup
throw;
}
catch (exception_type2&)
{
// Some cleanup
throw;
}
catch (exception_type3&)
{
// Some cleanup
throw;
}
Is there a well admited good practice regarding these situations?
© Programmers or respective owner